﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.MSRS
{
    class Class3
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故") )
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period > 0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("分红率(预估)");

                da.Value = ppa.TotalFee * f;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if ((ppa.Period + 1) % 2 == 0)
            {
                int d = (ppa.Period + 1) / 2;
                da.Value = ppa.Amount * (0.03 + (d - 1) * 0.005);
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.IsLastPeriod)
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("重疾"))
            {
                if (ppa.Period == 0)
                {
                    da.Value = ppa.TotalFee;
                }
                else
                {
                    da.Value = ppa.Amount;
                }
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("住院"))
            {
                if (ppa.Period == 0)
                {
                    da.Value = ppa.TotalFee;
                }
                else
                {
                    da.Value = ppa.Amount;
                }
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("住院"))
            {
                string bamt = ppa.PolicyActing.Policy.SelectedColRateFactors["住院补贴"];

                int day = Convert.ToInt32(ppa.PolicyActing.SchemeActing.GetAuxConfigValue("住院天数"));

                day = day > 180 ? 180 : day;

                int b = int.Parse(bamt.Trim());

                da.Value = day * b;
                da.Description = "最多180天";
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("特别重疾"))
            {
                ppa.SchemePeriodActing.InsurantStates.Add("重疾");
                da.Value = ppa.Amount * 0.5;
            }

            if (ppa.SchemePeriodActing.InsurantStates.Contains("重疾"))
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
                ppa.SchemePeriodActing.BasicPolicyPeriodActing.IsCurrentFinish = true;
            }
            
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("住院"))
            {
                da.Value = ppa.Amount;
                da.Description = "必须且合理的实际医疗费用";
            }

        }
        //复利计算
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                int p = ppa.IsAtPaymentPeriod ? ppa.Period + 1 : ppa.PolicyActing.Policy.PaymentPeriodLength;

                double f = ppa.PolicyActing.Policy.Fee;
                double s = 0;

                for (int i = 0; i <= ppa.Period; i++)
                {
                    IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[i];

                    s = s * 1.025 + pppa.Fee;
                }

                da.Value = s;

                ppa.IsCurrentFinish = true;
            }

        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.IsLastPeriod)
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
            }

        }
    }
}
